package cn.kinoko.controller.oss;

import cn.kinoko.common.base.model.Result;
import cn.kinoko.service.minio.MinioService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

/**
 * @author kinoko
 */
@RestController
@RequestMapping("/file")
public class FileController {

    @Resource
    private MinioService minioService;

    @PostMapping("/upload")
    public Result<String> uploadMg(@RequestParam("prefix") String prefix,
                                   @RequestParam("datePrefix") Boolean datePrefix,
                                   @RequestParam("file") MultipartFile multipartFile) throws Exception {
        return Result.success(minioService.uploadFile(prefix,
                multipartFile.getOriginalFilename(),
                multipartFile.getContentType(),
                multipartFile.getInputStream(),
                datePrefix));
    }

    @PostMapping("/uploadBatch")
    public Object uploadBatch(@RequestParam("name") String name,
                              @RequestParam("ep") Integer ep,
                              @RequestParam("file") MultipartFile[] files) throws Exception {
        return minioService.uploadBatch(name + "/" + ep, files, false);
    }

}
